﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ArduinoComController;

namespace ArduinoComUserinterface
{
    public partial class ArduinoComForm : Form
    {
        public ArduinoComController.ArduinoCom arduinoCom;
        
        public ArduinoComForm()
        {
            InitializeComponent();
            InitializeFormComponents();
            ;
        }

        private void InitializeFormComponents()
        {
            foreach (string portName in System.IO.Ports.SerialPort.GetPortNames())
            {
                this.comboBoxComport.Items.Add(portName);
            }

            foreach(string comCommand in Enum.GetNames(typeof(ArduinoCom.ComCommand)))
            {
                this.comboBox1Command.Items.Add(comCommand);
            }

            

        }

        private void comboBoxComport_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selectedComport = comboBoxComport.SelectedItem.ToString();
            arduinoCom = new ArduinoCom(selectedComport);

        }

        private void buttonSendCommand_Click(object sender, EventArgs e)
        {
            var comCommand = (ArduinoCom.ComCommand) Enum.Parse(typeof (ArduinoCom.ComCommand), this.comboBox1Command.SelectedItem.ToString());
            short inputvalue = System.Convert.ToInt16(this.textBoxCommandValue.Text);

            var output = arduinoCom.sendCmd(comCommand, inputvalue);

            this.textBoxCommandOutput.Text = System.Convert.ToString(output);

        }
    }
}
